﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace PSE.Communication.Fix.Common
{
    public class ConverterFactory
    {
        public static IFixModelConverter<T> GetModelConverter<T>() where T : BaseEntity
        {
            IFixModelConverter<T> instance = null;

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.IsClass)
                {
                    try
                    {
                        InterfaceMapping map = type.GetInterfaceMap(typeof(IFixModelConverter<T>));

                        instance = (IFixModelConverter<T>)Activator.CreateInstance(type);

                        break;
                    }
                    catch (ArgumentException)
                    {

                    }
                }
            }

            return instance;
        }
    }
}
